// view/my/xinxilr/xinxilr.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: '',
    yuming: yuming,
    heights: '',
    title: "信息录入",
    indicatorDots: false,
    autoplay: false,
    interval: 5000,
    duration: 1000,
    // huan: ['从业人员二维码', '供应商二维码', '溯源二维码'],
    currtab: 0,
    swiperIndex: 0,
  },
  // 从业人员 ：practitioner
  // 防疫上报 ： Epidemic
  // 原料 ：  material
  // 供应商 ： supplier 
  shengc(e) {
    var url = e.currentTarget.dataset.url
    var name = e.currentTarget.dataset.name
    console.log(url)
    console.log(name)
    // 生成二维码
    wx.showLoading({
      title: '生成中...',
    })
    this.myRequest(yuming + 'Besall/fromAppletQrimg', {
      scene: wx.getStorageSync('shopId') + '_' + name + '_' + 'EabEnd' + '_1',
      page: url,
      from: 'EabEnd',
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      wx.hideLoading()
      console.log(res.data.data)
      console.log(">>>>>>>>>>>>>")
      this.myRequest(yuming + 'shop/shopSaveQrimages', {
        shopId: wx.getStorageSync('shopId'),
        tagers: name,
        qrUrl: res.data.data,
      }, "POST").then(res => {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
        this.list()
      })
    })
  },

  list() {
    wx.showLoading({
      title: '加载...'
    })
    this.myRequest(yuming + 'shop/shopSelectQrimages', {
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      wx.hideLoading({})
      this.setData({
        ulist: res.data.data
      })
      console.log(this.data.ulist)
      console.log(this.data.swiperIndex)
      if (this.data.ulist[this.data.swiperIndex].data != null) {
        this.setData({
          sunimg: this.data.ulist[this.data.swiperIndex].data.qrUrl
        })
        console.log(this.data.sunimg)
      }
    })
  },
  // qies(e) {
  //     console.log(e)
  //     console.log('>>>>>>>>>>>')
  //     var index = e.currentTarget.dataset.currtab
  //     this.setData({
  //         currtab: index
  //     })
  // },
  // 方法 
  swiperChange(e) {
    console.log(e)
    let that = this
    that.setData({
      swiperIndex: e.detail.current,
    })
    console.log(that.data.swiperIndex)
    if (this.data.ulist[this.data.swiperIndex].data != null) {
      this.setData({
        sunimg: this.data.ulist[this.data.swiperIndex].data.qrUrl
      })
      console.log(this.data.sunimg)
    }
  },
  backs() {
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5
    })
    this.list()
    console.log(this.data.swiperIndex)
    console.log(this.data.ulist)

  },
  fasong() {
    var that = this
    wx.showModal({
      title: '提示',
      content: '二维码需慎重发送，您确定发送吗？',
      success(res) {
        if (res.confirm) {
          that.song()
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  song() {
    wx.downloadFile({
      url: this.data.sunimg, // 分享的图片的链接
      success: (res) => {
        wx.showShareImageMenu({
          path: res.tempFilePath
        })
      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})